import matplotlib.pyplot as plt

# 数据
anchors = [2, 3, 4, 5]
silhouette_scores = [0.9978,0.5783,0.5901,0.5456,0.5489]  # 从图中读取的 Silhouette 分数
map_scores = [0.87008, 0.86888,0.8686, 0.86986]  # 提供的 mAP 数据

fig, ax1 = plt.subplots()

# # 绘制 Silhouette 分数
# ax1.set_xlabel("Number of Anchors (k)")
# ax1.set_ylabel("Silhouette Score", color="tab:blue")
# ax1.plot(anchors, silhouette_scores, "o-", color="tab:blue", label="Silhouette Score")
# ax1.tick_params(axis="y", labelcolor="tab:blue")

# 创建一个共享 x 轴的第二个 y 轴
ax2 = ax1.twinx()
ax2.set_ylabel("mAP", color="tab:green")
ax2.plot(anchors, map_scores, "s-", color="tab:green", label="mAP")
ax2.tick_params(axis="y", labelcolor="tab:green")

fig.tight_layout()  # 确保子图不会重叠
plt.title("Silhouette Score and mAP vs Number of Anchors")
plt.show()
